import redis

# 配置 Redis 地址和端口
host = '172.19.251.204'
port = 6379

# 要查询的数据库编号
dbs = [0, 1, 2, 3]

for db in dbs:
    # 创建连接时指定 db=0，然后用 select 切换（为了兼容 StrictRedis 的行为）
    r = redis.StrictRedis(host=host, port=port, db=0, decode_responses=True)
    r.execute_command('SELECT', db)  # 切换到目标数据库

    keys = r.keys('*')  # 获取所有 key

    print(f"Database {db} keys:")
    if keys:
        for key in keys:
            print("  " + key)
    else:
        print("  (empty)")
    print("-" * 40)